package myJs.myPkg

import myJs.Implicits._
import myJs.myPkg.highcharts._
import myJs.myPkg.jquery.JQuery
import myJs.tool.Pojo.HighchartsOptions

import scala.scalajs.js
import scala.scalajs.js.Dynamic.{global => g}
import scala.scalajs.js.JSON
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.JSConverters._
import upickle.default._

/** Created by yz on 9/4/2020
  */

@js.native
trait HighchartsJQuery extends js.Object {

  def highcharts(kind: String, config: HighchartsConfig): JQuery = js.native

}

object Highcharts {

  def chart(jq: JQuery, config: HighchartsConfig) = {
    g.Highcharts.chart(jq(0), config)
  }

  def mapChart(jq: JQuery, config: HighchartsConfigBuilder) = {
    g.Highcharts.mapChart(jq(0), config)
  }

  def chart(divId: String, config: HighchartsConfig) = {
    g.Highcharts.chart(divId, config)
  }

  def getOptions(): HighchartsOptions = {
    val dict = g.Highcharts.getOptions().toJDJAn

    read[HighchartsOptions](JSON.stringify(dict))
  }

}

trait HighchartsJQueryImplicits {

  implicit def implicitHighchartsJQuery(jq: JQuery): HighchartsJQuery = {
    jq.asInstanceOf[HighchartsJQuery]
  }
}

@js.native
@JSGlobal("Highcharts.Color")
class HighchartsColor(input: String) extends js.Object {

  def brighten(alpha: Double): HighchartsColor = js.native

  def get(): String = js.native

}
